﻿using FastMvc.Auth;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastMvc.Filters
{
    /// <summary>
    /// 设置UserAuth信息用的Fitler
    /// TO_DO 有没有更加优雅一点的？
    /// </summary>
    public class UserSetActionFilter : IActionFilter
    {
        public void OnActionExecuted(ActionExecutedContext context)
        {
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            var user = context.HttpContext.Items["UserAuth"] as UserAuthInfo;
            if (user != null)
            {
                (context.Controller as BaseController)?.SetUserAuth(user);
            }
        }
    }
}
